﻿using System;
using System.Data;

namespace ConfExpert.Forms.ImportWizards
{
    public partial class CafeCoton_Tip1 : XITopCekiListesi
    {
        int YuklemeId;
        public CafeCoton_Tip1(int YuklemeId) :
            base(YuklemeId)
        {
            InitializeComponent();

            this.YuklemeId = YuklemeId;
            Init("CAFE COTON Tip1 Çeki Listesi", true);
            this.FileDone += CafeCoton_Tip1_FileDone;
        }

        void CafeCoton_Tip1_FileDone(DataSet Data, string FileName)
        {
            DataTable dt = Data.Tables[0];
            DataRowCollection rows = dt.Rows;
            DataColumnCollection cols = dt.Columns;        
            
            for  ( int colIndex = 0; colIndex < dt.Columns.Count ; colIndex++)
            {
                DataRow dr0 = dt.Rows[0];
                switch (dr0[colIndex].ToString())
                {
                    case "LotNo": dt.Columns[colIndex].ColumnName = "LotNo"; break;
                    case "VendorRollId": dt.Columns[colIndex].ColumnName = "VendorRollId"; break;
                    case "Qty": dt.Columns[colIndex].ColumnName = "Qty"; break;                                                          
                    case "Article": dt.Columns[colIndex].ColumnName = "Article"; break;
                    //case "Brand": dt.Columns[colIndex].ColumnName = "Brand"; break;
                    //case "Season": dt.Columns[colIndex].ColumnName = "Season"; break;
                    //case "OrderRef": dt.Columns[colIndex].ColumnName = "OrderRef"; break;  
                }                    
            }

            foreach (DataRow dr in dt.Rows)
            {
                try
                {
                    string article = dr["Article"].ToString();
                    if (Article.Select("Article='" + article + "'").Length == 0)
                    {
                        DataRow drArticle = Article.NewRow();
                        drArticle["Article"] = article;                        
                        Article.Rows.Add(drArticle);
                    }
                    DataRow drRoll = Roll.NewRow();
                    drRoll["Article"] = article;
                    drRoll["VendorRollId"] = dr["VendorRollId"];
                    drRoll["Qty"] = dr["Qty"];
                    drRoll["LotNo"] = dr["LotNo"];

                    //drRoll["Brand"] = dr["Brand"];
                    //drRoll["Season"] = dr["Season"];
                    //drRoll["OrderRef"] = dr["OrderRef"];

                    //drRoll["AyrimId"] = dr["AyrimId"];

                    Roll.Rows.Add(drRoll);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
               
        
    }
}


